#include "StdAfx.h"
#include "StringConverter.h"


BOOL CStringToChar( char* out, const CString& cstr )
{
#if defined UNICODE
	return WcharToChar( out, cstr );
#else
	const char* cstr_buf = cstr.GetBuffer();
	long len = strlen( cstr_buf );
	strcpy( out, cstr_buf, len );
	out[len] = 0;
	cstr.ReleaseBuffer();

	return TRUE;
#endif
}

CString CharToCString( const char* str )
{
#if defined UNICODE
	long str_len = strlen( str );

	WCHAR* wchar = new WCHAR[str_len + 1];
	mbstowcs( wchar, str, str_len );
	wchar[str_len] = 0;
	CString cstr( wchar );
	delete wchar;

	return cstr;
#else
	return CString( str );
#endif
}

BOOL WcharToChar( char* out, const WCHAR* wstr )
{
	long wstr_len = wcslen( wstr );
	wcstombs( out, wstr, wstr_len );

	out[wstr_len] = 0;

	return TRUE;
}

BOOL CharToWchar( WCHAR* out, const char* str )
{
	long str_len = strlen( str );
	mbstowcs( out, str, str_len );

	out[str_len] = 0;

	return TRUE;
}
